/**
 * excel
*
*/
var express = require('express');
var request = require('request');

var url = require('url');
var qstr = require("querystring");
var fs = require("fs");
var xlsx = require('node-xlsx');
var pro = require('../../property/cuspro');
var auth = require('../../auth/auth');
var util = require('../../util/commonutil');
var router = express.Router();
// var querystring = require('querystring');

/* GET import excel test. */
router.get('/importExcel', function(req, res, next) {
    var filename='./public/test.xlsx';
    console.error(filename);
    // read from a file
    var obj = xlsx.parse(filename);
    console.log(JSON.stringify(obj));

    res.send('import successfully!');
});
/* GET export excel test. */
router.get('/exportExcel', function(req, res, next) {
// write
    var data = [[1,2,3],[true, false, null, 'sheetjs'],['foo','bar',new Date('2014-02-19T14:30Z'), '0.3'], ['baz', null, 'qux']];
    var buffer = xlsx.build([{name: "mySheetName", data: data}]);
    fs.writeFileSync('b.xlsx', buffer, 'binary');
    res.setHeader("Content-Disposition", "attachment; filename=b.xlsx;");
    res.setHeader("Content-Type", "application/vnd.ms-excel")
    res.send('export successfully!');

});
module.exports = router;
